//C13:ep13_3.c: enter 4 students' datas, store then to a file.
#include <stdio.h>
#include <stdlib.h>

#define SIZE 4
struct student_st
{
    char name[15];
    int num;
    int age;
    char addr[20];
}stud[SIZE];

void save1()
{
    FILE *fp;
    int i;
    if((fp = fopen("stu_list.txt", "w")) == NULL)
    {
        fprintf(stderr, "cannot open file!");
        return;
    }

    for(i = 0; i < SIZE; i++)
    {
        if(fwrite(&stud[i], sizeof(struct student_st), 1, fp) != 1)
        {
            fprintf(stderr, "file write error!");
            //exit(1);
        }
    }
    fclose(fp);
}

int main(void)
{
    int i;
    for(i = 0; i < SIZE; i++)
    {
        scanf("%s%d%d%s", &stud[i].name, &stud[i].num, 
                &stud[i].age, &stud[i].addr);
    }
    save1();
    exit(0);
}
